# Maintainer: Hoang Nguyen <folliekazetani@protonmail.com>
pkgname=mabel
pkgver=0.1.3
pkgrel=0
pkgdesc="Fancy BitTorrent client for the terminal written in Go"
url="https://github.com/smmr-software/mabel"
arch="all"
license="GPL-3.0-or-later"
makedepends="go"
source="$pkgname-$pkgver.tar.gz::https://github.com/smmr-software/mabel/archive/refs/tags/v$pkgver.tar.gz
	anacrolix-mmsg-support-riscv64.patch.noauto
	"

export GOMODCACHE="$srcdir/go"
export GOFLAGS="$GOFLAGS -modcacherw"

prepare() {
	default_prepare

	case $CARCH in
		riscv64)
			go mod download
			chmod -R +w "$GOMODCACHE"

			patch -p1 \
				-d "$GOMODCACHE/github.com/anacrolix/mmsg@v1.0.0" \
				-i "$srcdir"/anacrolix-mmsg-support-riscv64.patch.noauto
		;;
	esac
}

build() {
	local _ldflags="
	-X main.version=v$pkgver
	-X main.commit=AlpineLinux
	-X main.date=$(date +%FT%T%Z)
	"
	go build -v -o bin/$pkgname -ldflags "$_ldflags"
}

check() {
	go test ./...
}

package() {
	install -Dm755 bin/$pkgname -t "$pkgdir"/usr/bin
}

sha512sums="
b7e4ad8b9cc8fb2818c719294700a6452da49ce6d614343b6aff465c1346cc49c43f1114211433f6995faef093cbfd99270e4e889dd66948d32be31e98f35d06  mabel-0.1.3.tar.gz
b131472e22217bf25af5eb244f753cf9b2e97844c62bbe8fbadee61b34b3d7f21d6a272233db29faf2e7e6d9f6e1148aced4c7aa35f9bc7998395e7b5e174b46  anacrolix-mmsg-support-riscv64.patch.noauto
"
